#include "Background.h"
#include "Constants.h"
#include <content\Material.h>

void BackgroundAction::update( float elapsed ) {
	m_Timer += elapsed;
	ds::Vec3 position = ds::Vec3(
		cos(m_Timer / starsParallaxPeriod),
		sin(m_Timer / starsParallaxPeriod),
		0.0f) *
		starsParallaxAmplitude;	
	ds::Shader& shader = gEngine->getResourceManager().getShader(m_ShaderHandle);
	shader.setVec3("position",position);

	if ( m_Fading ) {
		ds::Shader& stripesShader = gEngine->getResourceManager().getShader(m_StripesHandle);
		m_FadeTimer += elapsed;
		if ( m_FadeTimer > FADE_TTL ) {
			m_Fading = false;
			m_FadeTimer = 0.0f;
		}
		stripesShader.setFloat("timer",m_FadeTimer);
	}
}

void BackgroundAction::process( ds::EventBuffer& buffer ) {
	if ( buffer.containsID(EVN_START_FADING) ) {
		m_FadeTimer = 0.0f;
		m_Fading = true;
	}
}
